package com.tsing.cli.common.core.util;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Validator;

import java.util.Set;

/**
 * Validator 校验工具类
 *
 * @author TheTsing
 */
public class ValidatorUtil {

    private static final Validator VALIDATOR = SpringUtils.getBean(Validator.class);

    public static <T> void validate(T object, Class<?>... groups) {
        Set<ConstraintViolation<T>> validate = VALIDATOR.validate(object, groups);
        if (!validate.isEmpty()) {
            throw new ConstraintViolationException(validate);
        }
    }

}
